﻿/*
 * Created by SharpDevelop.
 * User: phtrung
 * Date: 4/17/2009
 * Time: 11:04 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System.Windows.Forms;
using System.Drawing;
using System.Data;
using System.Collections;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices; 
using System.Drawing.Imaging;
using popLib.ExtensionClass;
using System.IO;
using System.Reflection;

namespace popLib
{
	/// <summary>
	/// Description of Interfacer.
	/// </summary>
		
	
	
	public abstract class SidebarContainer:Form{
		public abstract void ReloadSidebar();
		public virtual void ActivateSidebar(){ this.Activate(); }
		public abstract void ShowBalloonTip( string title, string message, ToolTipIcon toolTipIcon);
	}
	
	public interface ISidebarGadget{
		string Name{get;}
		string Description { get; }
		string Thumbnail { get; }
		Hashtable Options { get; set; }
		
		object InitGadget();	    
	    void ViewOptions();	    
	    void UpdateOptions(bool reloadSidebar);	    
	    void Dispose();
	    
	}
	
	public abstract class SidebarGadget:ISidebarGadget{
		
		public Profile ini_config;
		public SidebarControl control;
		public SidebarGadgetOption sidebarGadgetOption;		
		public SidebarContainer sidebarContainer;
		public string file_config = Path.Combine( Path.GetDirectoryName(Assembly.GetCallingAssembly().Location), "setting.ini");
		
		public SidebarGadget(SidebarContainer sidebarContainer){
			this.sidebarContainer = sidebarContainer;
			ini_config  = ProfileLib.initProfile( ProfileLib.ProfileType.Ini, file_config );
		}
		
		public virtual string Name{ get{ return ini_config.getValue("Setting", "Name"); } }
	    public virtual string Description { get{ return ini_config.getValue( "Setting", "Description"); } }
	    public virtual string Thumbnail { get{ return Path.ChangeExtension(Assembly.GetExecutingAssembly().Location, "png"); } }
	    public virtual Hashtable Options { 
	    	get{ return StringLib.parseOption( ini_config.getValue("Setting", "Options") ); }
	    	set{
	    		ini_config.setValue( "Setting", "Options", StringLib.deParseOption(value) );
	    		UpdateOptions(true);
	    	}
	    }
	    public abstract object InitGadget();
	    
	    public abstract void ViewOptions();
	    
	    public virtual void UpdateOptions(bool reloadSidebar){
	    	if( control == null ) return;
	    	control.StartComponent();
	    	if( reloadSidebar ) sidebarContainer.ReloadSidebar();
	    }
	    
	    public virtual void Dispose(){
	    	control.Dispose();
			if(sidebarGadgetOption != null) sidebarGadgetOption.Close();
	        GC.SuppressFinalize(this);
	        GC.Collect();
	    }
	}
	
	public abstract class SidebarControl:UserControl{
		public SidebarGadget sidebarGadget;
		public SidebarControl(SidebarGadget sidebarGadget){
			this.sidebarGadget = sidebarGadget;
		}
		public abstract void StartComponent();
	}
	
	public abstract class SidebarGadgetOption:Form{
		public SidebarGadget sidebarGadget;
		public SidebarGadgetOption(SidebarGadget sidebarGadget){
			this.sidebarGadget = sidebarGadget;
		}		
	}
}
